package com.itheima.executorService;

public class MyRunable implements Runnable{
    // 创建线程方式二：实现Runnable接口, 重写run方法, 创建Thread对象，调用start方法
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName() + ": PrimeThread2 run()");
        // 统计计算1-1000内的素数
        for (int i = 2; i <= 100; i++) {
            boolean flag = true;
            for (int j = 2; j * j <= i; j++) {
                if (i % j == 0) {
                    flag = false;
                    break;
                }
            }
            if (flag) {
                System.out.println(Thread.currentThread().getName() + "：得到的素数：" + i);
            }
        }
        try {
            Thread.sleep(10000000);
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
